<?php TPL::output('global/header_meta.tpl.htm'); ?>

<div class = "aw-register-box">
    <div class = "mod-head">
        <a href = ""><img src = "<?php echo G_STATIC_URL; ?>/css/<?php echo $this->template_name; ?>/img/login_logo.png" alt = ""/></a>
        <h1><?php _e('注册新用户'); ?></h1>
    </div>
    <div class = "mod-body">
        <form class = "aw-register-form form-horizontal" action = "account/ajax/register_process/" method = "post" id = "register_form">
            <?php if ($this->icode) { ?><input type = "hidden" name = "icode" id = "icode" value = "<?php echo $this->icode; ?>"/><?php } ?>
            <?php if ($this->return_url) { ?><input type = "hidden" name = "return_url" value = "<?php echo $this->return_url; ?>"/><?php } ?>

            <ul>
                <li class = "alert alert-danger collapse error_message text-left">
                    <i class = "icon icon-delete"></i> <em></em>
                </li>
                <!--<li>-->
                    <!--<input class = "aw-register-name form-control" type = "text" name = "user_name" placeholder = "<?php _e('用户名'); ?>" tips = "<?php _e('请输入一个 2-14 位的用户名');?>" errortips = "<?php _e('用户名长度不符合');?>" value = ""/>-->
                <!--</li>-->


                <?php if (get_setting('register_valid_type') == 'email') { ?>
                <li>
                    <input class = "aw-register-email form-control" type = "text" placeholder = "<?php _e('邮箱'); ?>" name = "email" tips = "<?php _e('请输入你常用的电子邮箱作为你的账号'); ?>" value = "<?php echo htmlspecialchars($_GET['email']); ?>" errortips = "<?php _e('邮箱格式不正确'); ?>"/>
                </li>
                <?php } ?>

                <?php if (get_setting('register_valid_type') == 'phone') { ?>
                <li>
                    <select class="form-control" name="countrycode" id="country-select"><option data-prefix="86" value="cn">中国</option><option data-prefix="886" value="tw">台湾地区</option><option data-prefix="852" value="hk">中国香港</option><option data-prefix="853" value="mo">中国澳门</option><option data-prefix="355" value="al">阿尔巴尼亚</option><option data-prefix="213" value="dz">阿尔及利亚</option><option data-prefix="93" value="af">阿富汗</option><option data-prefix="54" value="ar">阿根廷</option><option data-prefix="971" value="ae">阿联酋</option><option data-prefix="297" value="aw">阿鲁巴岛</option><option data-prefix="968" value="om">阿曼</option><option data-prefix="994" value="az">阿塞拜疆</option><option data-prefix="20" value="eg">埃及</option><option data-prefix="251" value="et">埃塞俄比亚</option><option data-prefix="353" value="ie">爱尔兰</option><option data-prefix="372" value="ee">爱沙尼亚</option><option data-prefix="376" value="ad">安道尔</option><option data-prefix="244" value="ao">安哥拉</option><option data-prefix="1264" value="ai">安圭拉</option><option data-prefix="1" value="ag">安提瓜和巴布达</option><option data-prefix="43" value="at">奥地利</option><option data-prefix="61" value="au">澳大利亚</option><option data-prefix="1246" value="bb">巴巴多斯</option><option data-prefix="675" value="pg">巴布亚新几内亚</option><option data-prefix="1242" value="bs">巴哈马群岛</option><option data-prefix="92" value="pk">巴基斯坦</option><option data-prefix="595" value="py">巴拉圭</option><option data-prefix="970" value="ps">巴勒斯坦领土</option><option data-prefix="973" value="bh">巴林岛</option><option data-prefix="507" value="pa">巴拿马</option><option data-prefix="55" value="br">巴西</option><option data-prefix="375" value="by">白俄罗斯</option><option data-prefix="1" value="bm">百慕大群岛</option><option data-prefix="359" value="bg">保加利亚</option><option data-prefix="1670" value="mp">北马里亚纳群岛</option><option data-prefix="229" value="bj">贝宁</option><option data-prefix="32" value="be">比利时</option><option data-prefix="354" value="is">冰岛</option><option data-prefix="591" value="bo">玻利维亚</option><option data-prefix="1" value="pr">波多黎各</option><option data-prefix="387" value="ba">波黑</option><option data-prefix="48" value="pl">波兰</option><option data-prefix="267" value="bw">博茨瓦纳</option><option data-prefix="501" value="bz">伯利兹</option><option data-prefix="975" value="bt">不丹</option><option data-prefix="226" value="bf">布基纳法索</option><option data-prefix="257" value="bi">布隆迪</option><option data-prefix="850" value="kp">朝鲜</option><option data-prefix="240" value="gq">赤道几内亚</option><option data-prefix="45" value="dk">丹麦</option><option data-prefix="49" value="de">德国</option><option data-prefix="670" value="tl">东帝汶</option><option data-prefix="228" value="tg">多哥</option><option data-prefix="1767" value="dm">多米尼加</option><option data-prefix="1809" value="do">多米尼加共和国</option><option data-prefix="7" value="ru">俄罗斯联邦</option><option data-prefix="503" value="sv">厄尔萨尔瓦多</option><option data-prefix="593" value="ec">厄瓜多尔</option><option data-prefix="291" value="er">厄立特里亚</option><option data-prefix="33" value="fr">法国</option><option data-prefix="298" value="fo">法罗群岛</option><option data-prefix="689" value="pf">法属玻里尼西亚</option><option data-prefix="594" value="gf">法属圭亚那</option><option data-prefix="63" value="ph">菲律宾</option><option data-prefix="358" value="fi">芬兰</option><option data-prefix="238" value="cv">佛得角</option><option data-prefix="500" value="fk">福克兰群岛 (马尔维纳斯)</option><option data-prefix="220" value="gm">冈比亚</option><option data-prefix="242" value="cg">刚果共和国</option><option data-prefix="243" value="cd">刚果民主共和国</option><option data-prefix="57" value="co">哥伦比亚</option><option data-prefix="506" value="cr">哥斯达黎加</option><option data-prefix="44" value="gg">格恩西岛</option><option data-prefix="1473" value="gd">格林纳达</option><option data-prefix="299" value="gl">格陵兰</option><option data-prefix="53" value="cu">古巴</option><option data-prefix="590" value="gp">瓜德罗普岛</option><option data-prefix="1671" value="gu">关岛</option><option data-prefix="592" value="gy">圭亚那</option><option data-prefix="7" value="kz">哈萨克斯坦</option><option data-prefix="509" value="ht">海地</option><option data-prefix="82" value="kr">韩国</option><option data-prefix="31" value="nl">荷兰</option><option data-prefix="599" value="an">荷属安的列斯</option><option data-prefix="382" value="me">黑山共和国</option><option data-prefix="504" value="hn">洪都拉斯</option><option data-prefix="686" value="ki">基里巴斯</option><option data-prefix="253" value="dj">吉布提</option><option data-prefix="996" value="kg">吉尔吉斯斯坦</option><option data-prefix="224" value="gn">几内亚</option><option data-prefix="245" value="gw">几内亚比绍</option><option data-prefix="1" value="ca">加拿大</option><option data-prefix="233" value="gh">加纳</option><option data-prefix="241" value="ga">加蓬</option><option data-prefix="855" value="kh">柬埔寨</option><option data-prefix="420" value="cz">捷克共和国</option><option data-prefix="263" value="zw">津巴布韦</option><option data-prefix="237" value="cm">喀麦隆</option><option data-prefix="974" value="qa">卡塔尔</option><option data-prefix="1" value="ky">开曼群岛</option><option data-prefix="269" value="km">科摩罗</option><option data-prefix="225" value="ci">科特迪瓦</option><option data-prefix="965" value="kw">科威特</option><option data-prefix="61" value="cc">可可群岛</option><option data-prefix="385" value="hr">克罗地亚</option><option data-prefix="254" value="ke">肯尼亚</option><option data-prefix="682" value="ck">库克群岛</option><option data-prefix="371" value="lv">拉脱维亚</option><option data-prefix="266" value="ls">莱索托</option><option data-prefix="856" value="la">老挝</option><option data-prefix="961" value="lb">黎巴嫩</option><option data-prefix="231" value="lr">利比里亚</option><option data-prefix="218" value="ly">利比亚</option><option data-prefix="370" value="lt">立陶宛</option><option data-prefix="423" value="li">列支敦士登</option><option data-prefix="262" value="re">留尼汪岛</option><option data-prefix="352" value="lu">卢森堡</option><option data-prefix="250" value="rw">卢旺达</option><option data-prefix="40" value="ro">罗马尼亚</option><option data-prefix="261" value="mg">马达加斯加</option><option data-prefix="356" value="mt">马耳他</option><option data-prefix="960" value="mv">马尔代夫</option><option data-prefix="265" value="mw">马拉维</option><option data-prefix="60" value="my">马来西亚</option><option data-prefix="223" value="ml">马里</option><option data-prefix="389" value="mk">马其顿</option><option data-prefix="692" value="mh">马歇尔群岛</option><option data-prefix="269" value="yt">马约特岛</option><option data-prefix="230" value="mu">毛里求斯</option><option data-prefix="222" value="mr">毛里塔尼亚</option><option data-prefix="1" value="us">美国</option><option data-prefix="1684" value="as">美属萨摩亚</option><option data-prefix="1340" value="vi">美属维尔京群岛</option><option data-prefix="976" value="mn">蒙古</option><option data-prefix="1664" value="ms">蒙特色拉特岛</option><option data-prefix="880" value="bd">孟加拉国</option><option data-prefix="51" value="pe">秘鲁</option><option data-prefix="691" value="fm">密克罗尼西亚联邦</option><option data-prefix="95" value="mm">缅甸</option><option data-prefix="373" value="md">摩尔多瓦</option><option data-prefix="212" value="ma">摩洛哥</option><option data-prefix="377" value="mc">摩纳哥</option><option data-prefix="258" value="mz">莫桑比克</option><option data-prefix="52" value="mx">墨西哥</option><option data-prefix="596" value="mq">那提尼克</option><option data-prefix="264" value="na">纳米比亚</option><option data-prefix="27" value="za">南非</option><option data-prefix="672" value="aq">南极洲</option><option data-prefix="977" value="np">尼泊尔</option><option data-prefix="505" value="ni">尼加拉瓜</option><option data-prefix="227" value="ne">尼日尔</option><option data-prefix="234" value="ng">尼日利亚</option><option data-prefix="683" value="nu">纽埃岛</option><option data-prefix="47" value="no">挪威</option><option data-prefix="672" value="nf">诺福克岛</option><option data-prefix="680" value="pw">帕劳群岛</option><option data-prefix="870" value="pn">皮特克恩岛</option><option data-prefix="351" value="pt">葡萄牙</option><option data-prefix="1868" value="tt">千里达及托巴哥</option><option data-prefix="81" value="jp">日本</option><option data-prefix="46" value="se">瑞典</option><option data-prefix="41" value="ch">瑞士</option><option data-prefix="685" value="ws">萨摩亚</option><option data-prefix="381" value="rs">塞尔维亚</option><option data-prefix="232" value="sl">塞拉利昂</option><option data-prefix="221" value="sn">塞内加尔</option><option data-prefix="357" value="cy">塞浦路斯</option><option data-prefix="248" value="sc">塞舌尔</option><option data-prefix="966" value="sa">沙特阿拉伯</option><option data-prefix="61" value="cx">圣诞岛</option><option data-prefix="239" value="st">圣多美及普林西比</option><option data-prefix="290" value="sh">圣赫勒拿</option><option data-prefix="1869" value="kn">圣克里斯多福和尼维斯</option><option data-prefix="1" value="lc">圣卢西亚岛</option><option data-prefix="378" value="sm">圣马力诺</option><option data-prefix="508" value="pm">圣皮瑞及麦克隆</option><option data-prefix="1" value="vc">圣文森及格瑞那丁</option><option data-prefix="94" value="lk">斯里兰卡</option><option data-prefix="421" value="sk">斯洛伐克共和国</option><option data-prefix="386" value="si">斯洛文尼亚</option><option data-prefix="268" value="sz">斯威士兰</option><option data-prefix="249" value="sd">苏丹</option><option data-prefix="597" value="sr">苏里南</option><option data-prefix="252" value="so">索马里</option><option data-prefix="677" value="sb">所罗门群岛</option><option data-prefix="992" value="tj">塔吉克斯坦</option><option data-prefix="66" value="th">泰国</option><option data-prefix="255" value="tz">坦尚尼亚</option><option data-prefix="676" value="to">汤加</option><option data-prefix="216" value="tn">突尼斯</option><option data-prefix="688" value="tv">图瓦卢</option><option data-prefix="90" value="tr">土耳其</option><option data-prefix="1649" value="tc">土克斯及开科斯群岛</option><option data-prefix="993" value="tm">土库曼斯坦</option><option data-prefix="690" value="tk">托克劳</option><option data-prefix="681" value="wf">瓦利斯及福杜纳群岛</option><option data-prefix="678" value="vu">瓦努阿图</option><option data-prefix="502" value="gt">危地马拉</option><option data-prefix="58" value="ve">委内瑞拉</option><option data-prefix="673" value="bn">文莱达鲁萨兰国</option><option data-prefix="256" value="ug">乌干达</option><option data-prefix="380" value="ua">乌克兰</option><option data-prefix="598" value="uy">乌拉圭</option><option data-prefix="998" value="uz">乌兹别克斯坦</option><option data-prefix="34" value="es">西班牙</option><option data-prefix="30" value="gr">希腊</option><option data-prefix="65" value="sg">新加坡</option><option data-prefix="687" value="nc">新喀里多尼亚</option><option data-prefix="64" value="nz">新西兰</option><option data-prefix="36" value="hu">匈牙利</option><option data-prefix="963" value="sy">叙利亚</option><option data-prefix="1" value="jm">牙买加</option><option data-prefix="374" value="am">亚美尼亚</option><option data-prefix="967" value="ye">也门</option><option data-prefix="964" value="iq">伊拉克</option><option data-prefix="98" value="ir">伊朗</option><option data-prefix="972" value="il">以色列</option><option data-prefix="39" value="it">意大利</option><option data-prefix="91" value="in">印度</option><option data-prefix="62" value="id">印度尼西亚</option><option data-prefix="44" value="gb">英国</option><option data-prefix="44" value="im">英属曼岛</option><option data-prefix="1284" value="vg">英属维尔京群岛</option><option data-prefix="962" value="jo">约旦</option><option data-prefix="84" value="vn">越南</option><option data-prefix="260" value="zm">赞比亚</option><option data-prefix="44" value="je">泽西岛</option><option data-prefix="235" value="td">乍得</option><option data-prefix="350" value="gi">直布罗陀</option><option data-prefix="56" value="cl">智利</option><option data-prefix="236" value="cf">中非共和国</option><option data-prefix="995" value="ge">佐治亚</option><option data-prefix="674" value="nr">瑙鲁</option><option data-prefix="39" value="va">梵蒂冈 (教廷)</option><option data-prefix="679" value="fj">斐济</option><option data-prefix="" value="oo">其他</option></select>
                </li>
                <li>
                    <!--<select class="">-->
                        <!--<option value="86">+86</option>-->
                        <!--<option value="86">+86</option>-->
                    <!--</select>-->

                    <input class = "aw-register-phone form-control" type = "text" name = "phone" placeholder = "<?php _e('手机号'); ?>" tips = "<?php _e('请输入一个常用的手机号');?>" errortips = "<?php _e('手机号不合法');?>" value = ""/>
                </li>
                <li class = "aw-register-mcode collapse">
                    <input class = "form-control pull-left" style = "width:228px;" name = "mcode" placeholder = "<?php _e('手机验证码'); ?>" type = "text" value = "">
                    <a href = "javascript:;" id="send-code" class = "btn btn-normal btn-blue">获取</a>
                </li>
                <?php } ?>

                <li>
                    <input class = "aw-register-pwd form-control" type = "password" name = "password" placeholder = "密码" tips = "<?php _e('请输入 6-16 个字符,区分大小写'); ?>" errortips = "<?php _e('密码不符合规则'); ?>"/>
                </li>
                <?php if (get_setting('register_seccode') == 'Y') { ?>
                <li class = "aw-register-verify">
                    <img class = "pull-right" id = "captcha" onclick = "this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" src = "">

                    <input type = "text" class = "form-control" name = "seccode_verify" placeholder = "<?php _e('验证码'); ?>"/>
                </li>
                <?php } ?>
                <li class = "last">
                    <label><input type = "checkbox" checked = "checked" value = "agree" name = "agreement_chk"/> <?php _e('我同意'); ?>
                    </label> <a href = "javascript:;" class = "aw-agreement-btn"><?php _e('用户协议'); ?></a>
                    <a href = "account/login/" class = "pull-right">已有账号?</a>
                    <div class = "aw-register-agreement collapse">
                        <div class = "aw-register-agreement-txt" id = "register_agreement"></div>
                    </div>

                </li>
                <li class = "clearfix">
                    <button class = "btn btn-large btn-blue btn-block" onclick = "AWS.ajax_post($('#register_form'), AWS.ajax_processer, 'error_message'); return false;"><?php _e('注册'); ?></button>
                </li>
            </ul>
        </form>
    </div>
    <div class = "mod-footer"></div>
</div>

<script type = "text/javascript">
    $(document).ready(function () {
        v = getCookieValue("secondsremained")?getCookieValue("secondsremained"):0;//获取cookie值
        if(v>0){
            settime($("send-code"));//开始倒计时
        }
        $.get(G_BASE_URL + '/account/ajax/register_agreement/', function (result) {
            $('#register_agreement').html(result.err);
        }, 'json');

        $('.aw-agreement-btn').click(function () {
            if ($('.aw-register-agreement').is(':visible')) {
                $('.aw-register-agreement').hide();
            }
            else {
                $('.aw-register-agreement').show();
            }
        });

//    $('.more-information-btn').click(function()
//    {
//        $('.more-information').fadeIn();
//        $(this).parent().hide();
//    });

        verify_register_form('#register_form');

        /* 注册页面验证 */
        function verify_register_form(element) {
            $(element).find('[type=text], [type=password]').on({
                focus: function () {
                    if (typeof $(this).attr('tips') != 'undefined' && $(this).attr('tips') != '') {
                        $(this).parent().append('<span class="aw-reg-tips">' + $(this).attr('tips') + '</span>');
                    }
                },
                blur: function () {
                    if ($(this).attr('tips') != '') {
                        switch ($(this).attr('name')) {
                            case 'user_name' :
                                var _this = $(this);
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 2) {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                if ($(this).val().length > 17) {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else {
                                    $.post(G_BASE_URL + '/account/ajax/check_username/',
                                            {
                                                username: $(this).val()
                                            }, function (result) {
                                                if (result.errno == -1) {
                                                    _this.parent().find('.aw-reg-tips').detach();
                                                    _this.parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + result.err + '</span>');
                                                }
                                                else {
                                                    _this.parent().find('.aw-reg-tips').detach();
                                                    _this.parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                                }
                                            }, 'json');
                                }
                                return;

                            case 'email' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                var emailreg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
                                if (!emailreg.test($(this).val())) {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                }
                                return;

                            case 'phone':
                                var _this = $(this);
                                $(this).parent().find('.aw-reg-tips').detach();
                                var phonereg = /^(13[0-9])|(14[0-9])|(15[0-9])|(18[0-9])|(17[0-9])\d{8}$/;
                                    if($("#country-select").val() != 'cn'){
//                                        $('.aw-register-mcode').fadeIn();
//                                        $('.aw-register-mcode').show();
                                    }else{
                                        if (!phonereg.test($(this).val())) {
                                            $(this).parent().find('.aw-reg-tips').detach();
                                            $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                            return;
                                        } else {
                                            $.post(G_BASE_URL + '/account/ajax/check_mobile/',
                                                    {
                                                        username: $(this).val()
                                                    }, function (result) {
                                                        if (result.errno == -1) {
                                                            _this.parent().find('.aw-reg-tips').detach();
                                                            _this.parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + result.err + '</span>');
                                                        }
                                                        else {
                                                            _this.parent().find('.aw-reg-tips').detach();
                                                            _this.parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                                            $('.aw-register-mcode').fadeIn();
                                                            $('.aw-register-mcode').show();
                                                        }
                                                    }, 'json');
                                        }
                                    }
                                return;

                            case 'password' :
                                $(this).parent().find('.aw-reg-tips').detach();
                                if ($(this).val().length >= 0 && $(this).val().length < 6) {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                if ($(this).val().length > 17) {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-err"><i class="aw-icon i-err"></i>' + $(this).attr('errortips') + '</span>');
                                    return;
                                }
                                else {
                                    $(this).parent().find('.aw-reg-tips').detach();
                                    $(this).parent().append('<span class="aw-reg-tips aw-reg-right"><i class="aw-icon i-followed"></i></span>');
                                }
                                return;

                        }
                    }

                }
            });
        }

//        $('.select_area').LocationSelect({
//            labels: ["<?php _e('请选择省份或直辖市'); ?>", "<?php _e('请选择城市'); ?>"],
//            elements: document.getElementsByTagName("select"),
//            detector: function () {
//                this.select(["<?php echo $this->user_info['province']; ?>", "<?php echo $this->user_info['city']; ?>"]);
//            },
//            dataUrl: G_BASE_URL.replace('/?', '') + '/static/js/areas.js'
//        });
        $('#send-code').click(function(e){
            var _this = $(this),
                c_code = $("#country-select").find('option:selected').data('prefix');
            if(c_code == 86){
                sendmsg(_this);
            }else{

            }
        });
        
        $("#country-select").change(function () {
            var code = $(".aw-register-mcode"),
                    mobile = $(".aw-register-phone");
//            if(!code.is(":hidden")){
//                code.hide();
//                mobile.val('');
//            }
        });
    });

    //发送验证码时添加cookie
    function addCookie(name,value,expiresHours){
        var cookieString=name+"="+escape(value);
        //判断是否设置过期时间,0代表关闭浏览器时失效
        if(expiresHours>0){
            var date=new Date();
            date.setTime(date.getTime()+expiresHours*1000);
            cookieString=cookieString+";expires=" + date.toUTCString();
        }
        document.cookie=cookieString;
    }
    //修改cookie的值
    function editCookie(name,value,expiresHours){
        var cookieString=name+"="+escape(value);
        if(expiresHours>0){
            var date=new Date();
            date.setTime(date.getTime()+expiresHours*1000); //单位是毫秒
            cookieString=cookieString+";expires=" + date.toGMTString();
        }
        document.cookie=cookieString;
    }
    //根据名字获取cookie的值
    function getCookieValue(name){
        var strCookie=document.cookie;
        var arrCookie=strCookie.split("; ");
        for(var i=0;i<arrCookie.length;i++){
            var arr=arrCookie[i].split("=");
            if(arr[0]==name){
                return unescape(arr[1]);
                break;
            }
        }

    }

    //开始倒计时
    var countdown;
    function settime(obj) {
        countdown=getCookieValue("secondsremained")?getCookieValue("secondsremained"):0;
        if (countdown == 0) {
            obj.removeAttr("disabled");
            obj.html("获取");
            return;
        } else {
            obj.attr("disabled", true);
            obj.html(countdown);
            countdown--;
            editCookie("secondsremained",countdown,countdown+1);
        }
        setTimeout(function() { settime(obj) },1000) //每1000毫秒执行一次
    }

    function sendmsg(obj){
        AWS.loading('show');
        var m = $('input[name=phone]').val();
        var c= $('input[name=captcha]').val();
//        if(c.length != 4){
//            AWS.alert('请输入验证码！');
//            AWS.loading('hide');
//            return false;
//        }
        var a = /^(13[0-9])|(14[0-9])|(15[0-9])|(18[0-9])|(17[0-9])\d{8}$/;
        if(!a.test(m)){
            AWS.alert('手机号输入不正确！');
            AWS.loading('hide');
            return false;
        }

        addCookie("secondsremained",60,60);//添加cookie记录,有效时间60s
        settime(obj);//开始倒计时
        $.post('account/ajax/sendmsg/',{m:m,c:c},function(e){
            AWS.loading('hide');
            if(e.success == true){
                AWS.alert('发送成功！');
            }else{
                if(e.errno != 1){
                    AWS.alert(e.err);
                }
            }
        },'json');
    }


</script>

<?php TPL::output('global/footer.tpl.htm'); ?>
